<template>
	<div class="page">
		<div class="login-box">
			<div class="login-form">
				<transition name="fade-transform" mode="out-in">
					<dingtalk-form v-if="isDingtalk" />
					<account-form v-else />
				</transition>
			</div>
		</div>
		<div
			style="position: absolute;
    bottom: 10%;
    left: 45%;"
		>
			<a
				style="color: #fff"
				target="_blank"
				href="https://beian.miit.gov.cn/#/Integrated/index"
				>闽ICP备2023007966号</a
			>
		</div>
	</div>
</template>

<script>
import qrcodeImg from "@/assets/img/qrcode.png";
import accountImg from "@/assets/img/account.png";
import AccountForm from "./components/account-form";
import DingtalkForm from "./components/dingtalk-form";
export default {
	name: "Login",
	components: {
		AccountForm,
		DingtalkForm
	},
	provide() {
		return {
			login: this
		};
	},
	data() {
		return {
			isDingtalk: true
		};
	},
	computed: {
		switchBtnImg() {
			return this.isDingtalk ? accountImg : qrcodeImg;
		}
	},
	created() {
		const { biz_id } = this.$route.query;
		// this.isDingtalk = code && state;
		this.isDingtalk = !!biz_id;

		// token过期之后强制刷新一次
		const isLoginReload = sessionStorage.getItem("isLoginReload");
		if (isLoginReload) {
			sessionStorage.removeItem("isLoginReload", true);
			location.reload();
			return false;
		}
	},
	methods: {
		switchType() {
			this.isDingtalk = !this.isDingtalk;
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	height: 100%;
	width: 100%;
	position: relative;
	background-color: $primary;
	background-image: url("~@/assets/img/bg1.png");
	background-size: cover;
	background-repeat: no-repeat;

	.login-box {
		text-align: center;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}
	.login-form {
		position: relative;
		width: 400px;
		box-sizing: border-box;
		box-shadow: 0px 2px 20px 0px rgba(51, 17, 55, 0.2);
		background: #fff;
		border-radius: 10px;
		.switch-btn,
		.tooltip {
			position: absolute;
			top: 8px;
		}
		.switch-btn {
			right: 8px;
			width: 50px;
			height: 50px;
			cursor: pointer;
		}
		.tooltip {
			right: 68px;
			font-size: 12px;
			color: #909399;
			height: 28px;
			line-height: 28px;
			padding: 0 8px;
			box-sizing: border-box;
			border: 1px solid #909399;
			border-radius: 3px;
			&::before,
			&::after {
				content: "";
				position: absolute;
				display: block;
				border-color: transparent;
				width: 0;
				height: 0;
				top: 50%;
				border-color: transparent;
			}
			&::before {
				right: -12px;
				margin-top: -6px;
				border-width: 6px;
				border-style: solid;
				border-left-color: #909399;
			}
			&::after {
				right: -10px;
				margin-top: -6px;
				border-width: 6px;
				border-style: solid;
				border-left-color: #fff;
			}
		}
	}
}
</style>
